<?php

namespace App\Requests\AdminMenu;

use App\Models\Admin;
use App\Models\AdminMenu;
use App\Requests\BaseRequest;

/**
 * @property int $id 该数据
 * @property string $menu_no 编码
 * @property string $name 名称
 * @property string $class_name 按钮类名
 * @property int $pid 上级ID
 * @property int $level 等级
 * @property int $type 类型
 * @property int $is_win 是否为窗口菜单
 * @property string $icon 图标
 * @property string $uri 路由
 * @property int $sort 排序，越小越靠前
 * @property int $btn_type 按钮类型
 * @property string $path_text
 * @property string $path
 * @property int $is_export 是否导出
 */
class StoreRequest extends BaseRequest
{
    /**
     * 定义规则信息
     *
     * @return array
     */
    public function rules()
    {
        return [
            'menu_no'    => 'required|string|max:255|unique:' . AdminMenu::tableName() . ',menu_no,' . ($this->id ?? 0) . ',id,is_delete,0',
            'name'       => 'required|string|max:255',
            'class_name' => 'nullable|string|max:255',
            'pid'        => 'nullable',
            'type'       => 'nullable|integer|min:1',
            'is_win'     => 'nullable|integer|min:1',
            'icon'       => 'nullable|string|max:255',
            'uri'        => 'nullable|string|max:255',
            'sort'       => 'nullable|integer|min:0',
            'btn_type'   => 'nullable|integer|min:1',
            'is_export'  => 'nullable',
        ];
    }

    /**
     * 定义字段对应的名称
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'id'         => '该数据',
            'menu_no'    => '编码',
            'name'       => '名称',
            'class_name' => '按钮类名',
            'pid'        => '上级ID',
            'level'      => '等级',
            'type'       => '类型',
            'is_win'     => '是否为窗口菜单',
            'icon'       => '图标',
            'uri'        => '路由',
            'sort'       => '排序，越小越靠前',
            'btn_type'   => '按钮类型',
            'path_text'  => '',
            'path'       => '',
            'is_export'  => '是否导出',
        ];
    }
}
